﻿package com.wandian.view.components.ui
{
	import com.wandian.ApplicationFacade;
	import com.wandian.controller.CLZNoticeName;
	import com.wandian.data.GameData;
	import com.wandian.model.AccountProxy;
	import com.wandian.model.vo.FaceVo;
	import com.wandian.model.vo.FriendVo;
	import com.wandian.model.vo.PlayerVo;
	import com.wandian.model.vo.PropVo;
	import com.wandian.model.vo.RoomVo;
	import com.wandian.util.CLZButton;
	import com.wandian.util.CLZLlistScrollPanel;
	import com.wandian.util.CLZLoadIcon;
	import com.wandian.util.CLZPanel;
	import com.wandian.util.CLZTabBar;
	import com.wandian.util.CLZTxtTip;
	import com.wandian.util.CLZZoom;
	import com.wandian.util.GlowFilterManage;
	import com.wandian.util.TextControl;
	import com.wandian.util.ToolTip;
	import com.wandian.util.loader.ImageLoader;

	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.MouseEvent;
	import flash.events.TextEvent;
	/**   
	* @author long
	* @QQ 108232706
	* @version 1.0   
	*/   
	public class PropGiftInfo extends EventDispatcher
	{
		private var _image:ImageLoader;
		private var _global:GameData;
		private var _mcGift:MovieClip;
		private var _propVo:PropVo;
		private var _num:int;
		private var _isShop:Boolean;
		private var facade:ApplicationFacade;
		private static const UP:uint=1;
		private static const OVER:uint=2;
		private static const DOWN:uint=3;

		public function PropGiftInfo(param1:MovieClip, param2:PropVo, param3:int, param4:Boolean=true):void
		{
			this._global=GameData.getInstance();
			this.facade=ApplicationFacade.getInstance();
			this._isShop=param4;
			this._num=param3;
			this._mcGift=param1;
			this._propVo=param2;
			this._mcGift.gotoAndStop(UP);
			this._mcGift.addEventListener(MouseEvent.CLICK, this.clickHandler);
			this._mcGift.addEventListener(MouseEvent.MOUSE_OVER, this.overHandler);
			this._mcGift.addEventListener(MouseEvent.MOUSE_OUT, this.outHandler);
			this._mcGift.buttonMode=true;
			this.initData();
			return;
		} 

		private function initData():void
		{
			if (this._isShop)
			{
				this._mcGift.nameTxt.text=this._propVo.name;
				this._mcGift.timerOverTxt.text=this._propVo.validity == 0 ? (GameData.tip["TIMEROVER"] + ":" + GameData.tip["FOREVENT"]) : (GameData.tip["TIMEROVER"] + ":" + this._propVo.validity + GameData.tip["DAY"]);
				this._mcGift.priceTxt.text=int(this._propVo.price * (this._propVo.discount / 100)) + GameData.tip["GOLD"];
				if (this._propVo.pcate <= 10)
				{
					if (this._propVo.bind == 0)
					{
						AddBtn.initBtn(this._mcGift, CLZNoticeName.BUYIN_PROP_TIP_WINDOW, AddBtn.OTHER, GameData.tip["BUYIN_NAME"], 1, 139, this._propVo, "OtherBtn3");
						AddBtn.initBtn(this._mcGift, CLZNoticeName.SEND_PROP_TIP_WINDOW, AddBtn.OTHER, GameData.tip["GIVE_NAME"], 51, 139, this._propVo, "OtherBtn2");
					}
					else
					{
						AddBtn.initBtn(this._mcGift, CLZNoticeName.BUYIN_PROP_TIP_WINDOW, AddBtn.OTHER, GameData.tip["BUYIN_NAME"], 30, 139, this._propVo, "OtherBtn3");
					}
					CLZLoadIcon.addIcon(this._mcGift.pic, this._propVo.url, 85, 85, 0, 0, "InitPropIcon", true);
				}
				else
				{
					CLZLoadIcon.addIcon(this._mcGift.pic, this._propVo.url, 85, 85, 0, 0, "InitGiftIcon", true);
				}
			}
			else
			{
				this._mcGift.nameTxt.text=this._propVo.name;
				if (this.propVo.validity == -1)
				{
					AddBtn.initBtn(this._mcGift, CLZNoticeName.RENEW_GIFT_REQ, AddBtn.OTHER, GameData.tip["RENEW"], 30, 139, this._propVo, "MinMinBtn");
					this._mcGift.priceTxt.text=int(this._propVo.price * (this._propVo.discount / 100) * (this._propVo.recount / 100)) + GameData.tip["GOLD"];
					this._mcGift.timerOverTxt.text=GameData.tip["REMAINING_OUT_TIME"];
					CLZLoadIcon.addIcon(this._mcGift.pic, this._propVo.url, 85, 85, 0, 0, "InitPropIcon", true);
				}
				else if (this._propVo.pcate <= 10)
				{
					this._mcGift.nameTxt.text=this._propVo.name;
					if (this._propVo.authority == 1)
					{
					}
					if (this._propVo.pframe != GameData.PROP_KICK_PFRAME_ID)
					{
					}
					if (this._propVo.pframe != GameData.PROP_BANSPEAK_PFRAME_ID)
					{
						AddBtn.initBtn(this._mcGift, CLZNoticeName.SHOW_USE_TIP, AddBtn.OTHER, GameData.tip["USE"], 30, 139, this._propVo, "MinMinBtn");
					}
					this._mcGift.timerOverTxt.text=GameData.tip["BUYIN_NUMBER_NAME"] + "：" + this._propVo.number;
					this._mcGift.priceTxt.text=this._propVo.validity == 0 ? (GameData.tip["TIMEROVER"] + ":" + GameData.tip["FOREVENT"]) : (GameData.tip["TIMEROVER"] + ":" + this._propVo.validity + GameData.tip["DAY"]);
					CLZLoadIcon.addIcon(this._mcGift.pic, this._propVo.url, 85, 85, 0, 0, "InitPropIcon", true);
				}
				else
				{
					if (this._propVo.state == 1)
					{
						AddBtn.addCurrentFunBtn(this._mcGift, this.onFunCancelGift, GameData.tip["CANCEL_GIFT_SHOW"], 30, 139, "MinMinBtn", this._propVo);
						this.clickThis();
					}
					else
					{
						AddBtn.addCurrentFunBtn(this._mcGift, this.onFunChangeGift, GameData.tip["UPDATE"], 30, 139, "MinMinBtn", this._propVo);
					}
					this._mcGift.priceTxt.text=GameData.replaceStrValue(GameData.tip["REMAINING_TIME"], "NUM", this._propVo.validity);
					if (this._global.userInfo.userVo.userid == this.propVo.fromMid)
					{
						this._mcGift.timerOverTxt.text=GameData.tip["MYSELF_BUYIN"];
					}
					else
					{
						this._mcGift.timerOverTxt.text=this.propVo.fromName + GameData.tip["GIVE_NAME"];
					}
					CLZLoadIcon.addIcon(this._mcGift.pic, this._propVo.url, 85, 85, 0, 0, "InitGiftIcon", true);
				}
			}
			return;
		} 

		private function onFunCancelGift(param1:PropVo=null):void
		{
			this.facade.sendNotification(CLZNoticeName.GIFT_CANCEL_REQ, param1);
			this.facade.sendNotification(CLZNoticeName.HIDE_ACCOUNT);
			return;
		} 

		private function onFunChangeGift(param1:PropVo=null):void
		{
			this.facade.sendNotification(CLZNoticeName.GIFT_UPDATE_REQ, param1);
			this.facade.sendNotification(CLZNoticeName.HIDE_ACCOUNT);
			return;
		} 

		private function overHandler(event:MouseEvent):void
		{
			GameData.playMcAllChild(this._mcGift.pic);
			this._mcGift.gotoAndStop(OVER);
			return;
		} 

		private function outHandler(event:MouseEvent):void
		{
			GameData.stopMcAllChild(this._mcGift.pic);
			this._mcGift.gotoAndStop(UP);
			return;
		} 

		private function clickHandler(event:MouseEvent):void
		{
			this.dispatchEvent(new Event(Event.CHANGE));
			return;
		} 

		public function recoveryState():void
		{
			if (!this._mcGift.hasEventListener(MouseEvent.CLICK))
			{
				this._mcGift.addEventListener(MouseEvent.CLICK, this.clickHandler);
				this._mcGift.addEventListener(MouseEvent.MOUSE_OVER, this.overHandler);
				this._mcGift.addEventListener(MouseEvent.MOUSE_OUT, this.outHandler);
			}
			this._mcGift.gotoAndStop(UP);
			this._mcGift.buttonMode=true;
			this._mcGift.maskBtn.mouseEnabled=true;
			return;
		} 

		public function clickThis():void
		{
			this._mcGift.removeEventListener(MouseEvent.CLICK, this.clickHandler);
			this._mcGift.removeEventListener(MouseEvent.MOUSE_OVER, this.overHandler);
			this._mcGift.removeEventListener(MouseEvent.MOUSE_OUT, this.outHandler);
			this._mcGift.gotoAndStop(DOWN);
			this._mcGift.buttonMode=false;
			this._mcGift.maskBtn.mouseEnabled=false;
			return;
		} 

		private function showAnimtionGift(param1:int):void
		{
			var _loc_2:*=GameData.getMovieClip("Gift" + param1);
			this._mcGift.pic.addChild(_loc_2);
			return;
		} 

		private function removeGift():void
		{
			var _loc_1:*=undefined;
			while (this._mcGift.pic.numChildren > 0)
			{

				_loc_1=this._mcGift.pic.removeChildAt(0);
				_loc_1=null;
			}
			return;
		} 

		public function get propVo():PropVo
		{
			return this._propVo;
		} 

		public function get mc():MovieClip
		{
			return this._mcGift;
		} 

		public function get num():int
		{
			return this._num;
		} 

	}
}
